//字符串缓存对象
function StringBuffer(){
	this.a = [];
}
StringBuffer.prototype.append = function(b){
	this.a.push(b);
}
StringBuffer.prototype.toString = function(){
	return this.a.join("");
}
StringBuffer.prototype.clear = function(){
	var c = this.a.length;
	for(var i=c;i>0;i--){
		this.a.pop();
	}
}

/**
 * 清空表单
 * f form选择器
 */
function clearForm(f){
	$(f).find(':input').not(':button, :submit, :reset, :radio').val('')
	.removeAttr('checked').removeAttr('selected');
}

/**
 * 填充对象到form中
 * o 对象
 * f form选择器
 */
function fillObjToForm(o,f){
	$(f).find("[name]").each(function(){
		var _this = $(this);
		var tagName = this.tagName.toLowerCase();
		var tmp = o[_this.attr("name")];
		if(!tmp){
			return true;
		}
		if(tagName=="input"){
			var type = _this.attr("type").toLowerCase();
			if(type=="text"||type=="hidden"){
				tmp = o[_this.attr("name")];
				if(tmp){
					_this.val(tmp);
				}
			}
		}else if(tagName=="textarea"){
			tmp = o[_this.attr("name")];
			if(tmp){
				_this.val(tmp);
			}
		}else if(tagName=="select"){
			tmp = o[_this.attr("name")];
			_this.children("option").each(function(){
				if(tmp==$(this).attr("value")){
					$(this).prop("selected",true);
					return true;
				}
			});
		}
	});
}

/**
 * 清空表单并填充对象到form
 * @param o
 * @param f
 * @return
 */
function clearAndFillForm(o,f){
	clearForm(f);
	fillObjToForm(o,f);
}